package Arrays101.Day01;

public class Day01_3 {
    public static void main(String[] args) {

        int[] ints = sortedSquares(new int[]{-4, -1, 0, 3, 10});
        for (int i = 0; i < ints.length; i++) {
            System.out.println(ints[i]);
        }
    }

    /**
     * Squares of a Sorted Array
     *
     * Given an integer array nums sorted in non-decreasing order, return an array of the squares
     * of each number sorted in non-decreasing order.
     * @param nums
     * @return
     */
    public static int[] sortedSquares(int[] nums) {
        for (int i = 0; i <nums.length ; i++) {
            double pow = Math.pow(nums[i], 2);
            int pow1 = (int) pow;
            nums[i]=pow1;
        }
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < nums.length-i-1; j++) {
                if (nums[j]>=nums[j+1]){
                    int temp;
                    temp=nums[j+1];
                    nums[j+1]=nums[j];
                    nums[j]=temp;
                }
            }
        }
        return nums;
    }
}
